package edu.pku.sei.modeler.model.notation.shape.extradata;

import org.eclipse.draw2d.Shape;
import org.w3c.dom.Element;

import edu.pku.notation.runtime.draw2d.RoundedRectangleFigure;
import edu.pku.sei.gefcommon.descriptor.annotation.FieldProperty;
import edu.pku.sei.modeler.model.core.MetaModelElement;
import edu.pku.sei.modeler.model.notation.core.NotationPackage;
import edu.pku.sei.modeler.model.xml.XMLUtility;

public class RoundedRectangleData  extends ExtraData {
	@FieldProperty(catalog="Extra",name="Corner Width",id="SHAPE_EXTRA_ROUNDEDRECTANGLE_WIDTH")
	private int width;
	@FieldProperty(catalog="Extra",name="Corner Height",id="SHAPE_EXTRA_ROUNDEDRECTANGLE_HEIGHT")
	private int height;
	
	public RoundedRectangleData(MetaModelElement host){
		super(host);
		setWidth(5);
		setHeight(5);
	}

	public void setWidth(int width) {
		this.width = width;
	}

	public int getWidth() {
		return width;
	}

	public void setHeight(int height) {
		this.height = height;
	}

	public int getHeight() {
		return height;
	}

	@Override
	public void refreshFigure(Shape shape) {
		edu.pku.notation.runtime.draw2d.RoundedRectangleFigure fig = (RoundedRectangleFigure) shape;
		fig.setCornerWidth(width);
		fig.setCornerHeight(height);
	}
	
	//add by fengchao
	public void serialize(Element root) {
		super.serialize(root);
		XMLUtility.xmlInstance.serializeAttribute(root, NotationPackage.ROUNDRECTANGLEDATA_HEIGHT, height);
		XMLUtility.xmlInstance.serializeAttribute(root, NotationPackage.ROUNDRECTANGLEDATA_WIDTH, width);
	}
	public void deSerialize(Element root) {
		super.deSerialize(root);
		height = XMLUtility.xmlInstance.deSerializeInt(root, NotationPackage.ROUNDRECTANGLEDATA_HEIGHT);
		width = XMLUtility.xmlInstance.deSerializeInt(root, NotationPackage.ROUNDRECTANGLEDATA_WIDTH);
	}
	//end add
	
}